package chapter06;

import java.util.HashMap;
import java.util.Scanner;

public class Test11_countWord {
    public static void main(String[] args) {
        System.out.println("请输入一个字符串：");
        Scanner scanner = new Scanner(System.in);
        String s = scanner.next();
        HashMap<Character, Integer> t = new HashMap<>();
        for(int i=0;i<s.length();i++){
            char c = s.charAt(i);
            //判断map是否存在键
            if(t.containsKey(c)){
                //先取出
                Integer integer = t.get(c);
                //加一再替换
                t.put(c,integer+1);
            }else{
                t.put(c,1);
            }
        }
        System.out.println(t);
    }
}
